package tm;

import org.junit.jupiter.api.Test;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * @author haoly
 * @title TMRuleTest
 * @date 2025/4/23 13:44
 * @description TODO
 */
public class TMRuleTest {
    @Test
    public void testAppliesTo(){
        TMRule<Integer> rule = new TMRule<>(1, '0', 2, '1', EnumDirection.RIGHT);
        System.out.println(rule);

        char blankChar = '_';
        Tape tape = new Tape(List.of(), '0', List.of(), blankChar);

        TMConfiguration<Integer> tmConfiguration = new TMConfiguration<>(1, tape);
        assertTrue(rule.appliesTo(tmConfiguration));

        tape = new Tape(List.of(), '1', List.of(), blankChar);
        tmConfiguration = new TMConfiguration<>(1, tape);
        assertFalse(rule.appliesTo(tmConfiguration));

        tape = new Tape(List.of(), '0', List.of(), blankChar);
        tmConfiguration = new TMConfiguration<>(2, tape);
        assertFalse(rule.appliesTo(tmConfiguration));

    }

    @Test
    public void testFollow(){
        TMRule<Integer> rule = new TMRule<>(1, '0', 2, '1', EnumDirection.RIGHT);
        System.out.println(rule);

        char blankChar = '_';
        Tape tape = new Tape(List.of(), '0', List.of(), blankChar);
        TMConfiguration<Integer> tmConfiguration = new TMConfiguration<>(1, tape);
        assertTrue(rule.appliesTo(tmConfiguration));

        System.out.println(rule.follow(tmConfiguration));

    }
}
